﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace Nivdal.Sponsors
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex--;
            this.ErrorLabel.Text = "";
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex++;
            //this.ErrorLabel.Text = MultiView1.ActiveViewIndex.ToString();
            this.ErrorLabel.Text = "";
            if (MultiView1.ActiveViewIndex.ToString() == "1")
            {
                if (this.EmailTextBox.Text.Trim() == "")
                    this.ErrorLabel.Text = Resources.SponsorsResource.NewSponsor_EmailIsRequire;

                else
                {
                    GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                    try
                    {
                        this.SecretQuestionLabel.Text = GND.ReadNivdalStringData("@Email", "Nivdal_NewSponsorGetSecretQuestion", this.EmailTextBox.Text.Trim());
                    }
                    catch
                    {
                        this.ErrorLabel.Text = "Error";
                    }

                    if (this.SecretQuestionLabel.Text == "")
                    {
                        this.ErrorLabel.Text = Resources.SponsorsResource.NewSponsor_Email;
                    }
                }
            }

           

        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            try
            {
                this.ErrorLabel.Text = GND.ReadNivdalStringData("@Email", "@SecretAnswer", "Nivdal_NewSponsorRecoverPassword", this.EmailTextBox.Text.Trim(), this.SecurityAnswerTextBox.Text.Trim());
                GND.SendPendingMails();
            }
            catch
            {
                this.ErrorLabel.Text = "Error";
            }

            if (this.ErrorLabel.Text == "" || this.ErrorLabel.Text == "Error")
            {
                this.ErrorLabel.Text = Resources.SponsorsResource.NewSponsor_IncorrectAnswer;
            }       

        }

        protected override void OnPreRender(EventArgs e)
        {
            ////if (MultiView1.ActiveViewIndex == MultiView1.Views.Count - 1)
            ////{
            ////    FillSummary();
            ////}

            btnBack.Visible = MultiView1.ActiveViewIndex > 0;
            btnNext.Visible = MultiView1.ActiveViewIndex < MultiView1.Views.Count - 1;
            btnSend.Visible = MultiView1.ActiveViewIndex == MultiView1.Views.Count - 1;
            base.OnPreRender(e);
        }

        ////private void FillSummary()
        ////{

        ////}

        protected void ResetButton_Click(object sender, EventArgs e)
        {

            MultiView1.ActiveViewIndex = 0;
            this.ErrorLabel.Text = "";
            this.EmailTextBox.Text = "";
            this.SecurityAnswerTextBox.Text = "";


        }
    }
}